package cn.jhc.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import uuntil.Constants;
import cn.jhc.bean.Song;
import cn.jhc.dao.Imp.GetAllUsers;
import cn.jhc.dao.Imp.GetSNOrSS;
import cn.jhc.db.SongDao;

/**
 * Servlet implementation class CheckSNOrSSServlet
 */
@WebServlet("/check2.do")
public class CheckSNOrSSServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	boolean b=true;
	List<Song> songSearch;
    public List<Song> getSongSearch() {
		return songSearch;
	}

	public void setSongSearch(List<Song> songSearch) {
		this.songSearch = songSearch;
	}

	public CheckSNOrSSServlet() {
        super();
        
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request, response);
	}
    
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String search=request.getParameter("search");
		SongDao.setSearch(search);
		DataSource dataSource = (DataSource)request.getServletContext().getAttribute(Constants.H2_DATASOURCE);
		response.setContentType("appliction/json;charset=utf8");

		try {
			b=GetSNOrSS.getSongNameOrSongSinger(dataSource, search);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		PrintWriter out=response.getWriter();
		out.print(b);
	}

}
